// hdu2665
// 题意：n(<=100000)个数，有m(<=100000)个询问，询问某一个区间的第k小的数。
//
// 题解：全局二分来做。二分的时候小心负数区间。
//
// run: $exec < input
#include <iostream>
#include <algorithm>

long long const inf = (1ll) << 30;
int const maxn = 200007;
int n, m;

struct data
{
	int type; // 1 data, 2 query
	long long v;
	int l, r, k; // kth biggest
	int cur, one_query;
	int ans_id, id;
};

data da[maxn], part1[maxn], part2[maxn];
long long ans[maxn];
int tree[maxn];

int lowbit(int x) { return x & -x; }

void bit_update(int id, int d)
{
	for (; id <= n; id += lowbit(id)) tree[id] += d;
}

int bit_sum(int id)
{
	int ret = 0;
	for (; id > 0; id -= lowbit(id)) ret += tree[id];
	return ret;
}

long long negtive_mid(long long l, long long r)
{
	long long mid = (l + r) / 2;
	if (mid < 0) mid--;
	return mid;
}

void divide_and_conquer(int head, int tail, long long l, long long r)
{
	if (head > tail) return;
	if (l == r) {
		for (int i = head; i <= tail; i++)
			if (da[i].type == 2) ans[da[i].ans_id] = l;
		return;
	}
	long long mid = negtive_mid(l, r);
	for (int i = head; i <= tail; i++)
		if (da[i].type == 1 && da[i].v <= mid) bit_update(da[i].id, 1);
		else if (da[i].type == 2) da[i].one_query = bit_sum(da[i].r) - bit_sum(da[i].l - 1);
	for (int i = head; i <= tail; i++)
		if (da[i].type == 1 && da[i].v <= mid) bit_update(da[i].id, -1);
	int tot1 = 0, tot2 = 0;
	for (int i = head; i <= tail; i++) {
		if (da[i].type == 2) {
			if (da[i].cur + da[i].one_query >= da[i].k)
				part1[++tot1] = da[i];
			else {
				da[i].cur += da[i].one_query;
				part2[++tot2] = da[i];
			}
		} else {
			if (da[i].v <= mid) part1[++tot1] = da[i];
			else part2[++tot2] = da[i];
		}
	}
	for (int i = 1; i <= tot1; i++) da[head + i - 1] = part1[i];
	for (int i = 1; i <= tot2; i++) da[head + i - 1 + tot1] = part2[i];
	divide_and_conquer(head, head + tot1 - 1, l, mid);
	divide_and_conquer(head + tot1, head + tot1 + tot2 - 1, mid + 1, r);
}

int main()
{
	std::ios::sync_with_stdio(false);
	int T; std::cin >> T;
	while (T--) {
		std::cin >> n >> m;
		long long min = inf, max = -inf;
		for (int i = 1; i <= n; i++) {
			da[i].type = 1;
			da[i].id = i;
			std::cin >> da[i].v;
			min = std::min(min, da[i].v);
			max = std::max(max, da[i].v);
		}
		for (int i = 1; i <= m; i++) {
			da[n + i].type = 2;
			da[n + i].ans_id = i;
			da[n + i].cur = 0;
			std::cin >> da[n + i].l >> da[n + i].r >> da[n + i].k;
		}
		divide_and_conquer(1, n + m, min, max);
		for (int i = 1; i <= m; i++)
			std::cout << ans[i] << '\n';
	}
}

